﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace SunCodeMaker
{
    public class Marker
    {
        #region 取得所有数据表
        /// <summary>
        /// 取得所有数据表
        /// </summary>
        /// <returns></returns>
        public static List<string> GetTables()
        {
            List<string> list = new List<string>();
            DataSet st = SqlHelper.Query("sp_tables  null,'dbo'");
            foreach (DataRow dr in st.Tables[0].Rows) { list.Add(dr[2].ToString()); }
            return list;
        }
        #endregion
        #region 取得指定表的所有列
        /// <summary>
        /// 取得指定表的所有列
        /// </summary>
        /// <param name="TalbeName"></param>
        /// <returns></returns>
        public static DataSet GetColumns(string TalbeName)
        {
            return SqlHelper.Query("sp_columns " + TalbeName);
        }
        #endregion
        #region 取得指定表的int identity主键
        /// <summary>
        /// 取得指定表的int identity主键
        /// </summary>
        /// <param name="rTalbes"></param>
        /// <returns></returns>
        public static string GetIndex(string TalbeName)
        {
            using (DataSet rTalbes = GetColumns(TalbeName))
            {
                foreach (DataRow dr in rTalbes.Tables[0].Rows)
                {
                    if (dr[5].ToString() == "int identity")
                    {
                        return dr[3].ToString();
                    }
                }
            }
            return null;
        }
        #endregion
        #region 取得指定表的主键信息
        /// <summary>
        /// 取得指定表的主键信息
        /// </summary>
        /// <param name="TableName"></param>
        /// <returns></returns>
        public static List<string> pKeys(string TableName)
        {
            DataSet st = SqlHelper.Query("EXEC sp_pkeys @table_name='" + TableName + "'");
            List<string> list = new List<string>();
            foreach (DataRow dr in st.Tables[0].Rows)
            {
                list.Add(dr[3].ToString());
            }
            return list;
        }
        #endregion

        #region 生成Model代码
        public static StringBuilder GetModelSB(string nameSpace, int choice, string TalbeName)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("using System;");
            sb.AppendLine("using System.Collections.Generic;");
            sb.AppendLine("using System.Text;");
            sb.AppendLine();
            if (!string.IsNullOrEmpty(nameSpace))
            {
                sb.AppendLine("namespace " + nameSpace + ".Model");
            }
            else
            {
                sb.AppendLine("namespace Model");
            }
            sb.AppendLine("{");
            sb.AppendLine("    [Serializable]");
            //根据不同的设置组合加载setCode方法
            sb.AppendLine(setsb(TalbeName, choice));
            return sb;
        }
        #endregion

        #region 生成BLL
        /// <summary>
        /// 生成BLL
        /// </summary>
        /// <returns></returns>
        public static StringBuilder GetBLLSB(string nameSpace, string TalbeName, bool MakeBy, bool add, bool Update, bool Delete, bool GetModel, bool GetList, bool Exists, bool GetMaxID)
        {
            DataSet Columns = Marker.GetColumns(TalbeName);
            string IdentityName = GetIndex(TalbeName);
            List<string> listP = pKeys(TalbeName);

            StringBuilder sb = new StringBuilder();
            sb.Append("using System;" + Environment.NewLine);
            sb.Append("using System.Data;" + Environment.NewLine);
            if (!string.IsNullOrEmpty(nameSpace))
            {
                sb.Append("using " + nameSpace + ".BLL;" + Environment.NewLine);
                sb.Append("using " + nameSpace + ".Model;" + Environment.NewLine);
                sb.Append("" + Environment.NewLine);
                sb.Append("namespace " + nameSpace + ".BLL" + Environment.NewLine);
            }
            else
            {
                sb.Append("using BLL;" + Environment.NewLine);
                sb.Append("" + Environment.NewLine);
                sb.Append("namespace BLL" + Environment.NewLine);
            }
            sb.Append("{" + Environment.NewLine);
            sb.Append("\tpublic class " + TalbeName + "" + Environment.NewLine);
            sb.Append("\t{" + Environment.NewLine);

            if (!string.IsNullOrEmpty(nameSpace))
            {
                sb.Append("\t  private readonly " + nameSpace + ".DAL." + TalbeName + " dal=new " + nameSpace + ".DAL." + TalbeName + "();" + Environment.NewLine);
            }
            else
            {
                sb.Append("\t  private readonly DAL." + TalbeName + " dal=new DAL." + TalbeName + "();" + Environment.NewLine);
            }

            sb.Append("\t  public " + TalbeName + "()" + Environment.NewLine + "\t  {}" + Environment.NewLine);
            sb.Append("\t  #region  成员方法" + Environment.NewLine);
            #region Add
            if (add)//add
            {
                //完成
                sb.Append("\t  /// <summary>" + Environment.NewLine + "\t  /// 增加一条数据" + Environment.NewLine + "\t  /// </summary>" + Environment.NewLine + Environment.NewLine);
                if (IdentityName != null)
                {
                    if (!string.IsNullOrEmpty(nameSpace))
                    {
                        sb.Append("\t  public int  Add(" + nameSpace + ".Model." + TalbeName + " model)" + Environment.NewLine);
                    }
                    else
                    {
                        sb.Append("\t  public int  Add(Model." + TalbeName + " model)" + Environment.NewLine);
                    }
                    sb.Append("\t  {" + Environment.NewLine);
                    sb.Append("\t     return dal.Add(model);" + Environment.NewLine);
                    sb.Append("\t  }" + Environment.NewLine);
                }
                else
                {
                    if (!string.IsNullOrEmpty(nameSpace))
                    {
                        sb.Append("\t  public int  Add(" + nameSpace + ".Model." + TalbeName + " model)" + Environment.NewLine);
                    }
                    else
                    {
                        sb.Append("\t  public int  Add(Model." + TalbeName + " model)" + Environment.NewLine);
                    }
                    sb.Append("\t  {" + Environment.NewLine);
                    sb.Append("\t     return dal.Add(model);" + Environment.NewLine);
                    sb.Append("\t  }" + Environment.NewLine);
                }

            }
            #endregion
            #region Update
            if (Update)//Update
            {
                sb.Append("\t  /// <summary>" + Environment.NewLine + "\t  /// 更新一条数据" + Environment.NewLine + "\t  /// </summary>" + Environment.NewLine + Environment.NewLine);
                if (!string.IsNullOrEmpty(nameSpace))
                {
                    sb.Append("\t  public void  Update(" + nameSpace + ".Model." + TalbeName + " model)" + Environment.NewLine);
                }
                else
                {
                    sb.Append("\t  public void  Update(Model." + TalbeName + " model)" + Environment.NewLine);
                }
                sb.Append("\t  {" + Environment.NewLine);
                sb.Append("\t     dal.UpDate(model);" + Environment.NewLine);
                sb.Append("\t  }" + Environment.NewLine);
            }
            #endregion
            #region Delete
            if (Delete)//Delete
            {
                //完成
                sb.Append("\t  /// <summary>" + Environment.NewLine + "\t  /// 删除一条数据" + Environment.NewLine + "\t  /// </summary>" + Environment.NewLine + Environment.NewLine);
                if (IdentityName != null)
                {
                    sb.Append("\t  public void  Delete(int " + IdentityName + " )" + Environment.NewLine);
                    sb.Append("\t  {" + Environment.NewLine);
                    sb.Append("\t     dal.Delete(" + IdentityName + ");" + Environment.NewLine);
                    sb.Append("\t  }" + Environment.NewLine);
                }
                else if (listP.Count != 0)//主键
                {
                    string DataType2 = "";
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        if (dr[3].ToString() == listP[0].ToString())
                        {
                            DataType2 = DataType.ConvertType(dr[5].ToString());
                            break;
                        }
                    }
                    sb.Append("\t  public void  Delete(" + DataType2 + " " + listP[0].ToString().Trim() + " )" + Environment.NewLine);
                    sb.Append("\t  {" + Environment.NewLine);
                    sb.Append("\t     dal.Delete(" + listP[0].ToString().Trim() + ");" + Environment.NewLine);
                    sb.Append("\t  }" + Environment.NewLine);
                }
                else if (IdentityName == null && listP.Count == 0)//自增 AND 主键 全无
                {
                    sb.Append("\t  public void Delete( ");
                    List<string> list1 = new List<string>();
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        list1.Add(DataType.ConvertType(dr[5].ToString() + " " + dr[3].ToString().ToString().Trim() + " "));
                    }
                    sb.Append(string.Join(",", list1.ToArray()));

                    sb.Append(" )" + Environment.NewLine);
                    sb.Append("\t  {" + Environment.NewLine);
                    sb.Append("\t     dal.Delete(");
                    List<string> list2 = new List<string>();
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        list2.Add(dr[3].ToString().ToString().Trim());
                    }
                    sb.Append(string.Join(",", list2.ToArray()));

                    sb.Append(");" + Environment.NewLine);
                    sb.Append("\t  }" + Environment.NewLine);
                }
            }
            #endregion
            #region GetModel
            if (GetModel)//GetModel
            {
                //完成
                sb.Append("\t  /// <summary>" + Environment.NewLine + "\t  ///  得到一个对象实体" + Environment.NewLine + "\t  /// </summary>" + Environment.NewLine + Environment.NewLine);
                if (IdentityName != null)
                {
                    if (!string.IsNullOrEmpty(nameSpace))
                    {
                        sb.Append("\t  public " + nameSpace + ".Model." + TalbeName + " GetModel(int " + IdentityName + " )" + Environment.NewLine);
                    }
                    else
                    {
                        sb.Append("\t  public Model." + TalbeName + " GetModel(int " + IdentityName + " )" + Environment.NewLine);
                    }
                    sb.Append("\t  {" + Environment.NewLine);
                    sb.Append("\t     return dal.GetModel(" + IdentityName + ");" + Environment.NewLine);
                    sb.Append("\t  }" + Environment.NewLine);
                }
                else if (listP.Count != 0)//主键
                {
                    string DataType2 = "";
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        if (dr[3].ToString() == listP[0].ToString())
                        {
                            DataType2 = DataType.ConvertType(dr[5].ToString());
                            break;
                        }
                    }
                    if (!string.IsNullOrEmpty(nameSpace))
                    {
                        sb.Append("\t  public " + nameSpace + "Model." + TalbeName + " GetModel(" + DataType2 + " " + listP[0].ToString().Trim() + " )" + Environment.NewLine);
                    }
                    else
                    {
                        sb.Append("\t  public Model." + TalbeName + " GetModel(" + DataType2 + " " + listP[0].ToString().Trim() + " )" + Environment.NewLine);
                    }
                    sb.Append("\t  {" + Environment.NewLine);
                    sb.Append("\t     return dal.GetModel(" + listP[0].ToString().Trim() + ");" + Environment.NewLine);
                    sb.Append("\t  }" + Environment.NewLine);
                }
                else if (IdentityName == null && listP.Count == 0)//自增 AND 主键 全无
                {
                    sb.Append("\t  public Maticsoft.Model." + TalbeName + " GetModel( ");
                    List<string> list1 = new List<string>();
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        list1.Add(DataType.ConvertType(dr[5].ToString() + " " + dr[3].ToString().ToString().Trim() + " "));

                    }
                    sb.Append(string.Join(",", list1.ToArray()));

                    sb.Append(" )" + Environment.NewLine);
                    sb.Append("\t  {" + Environment.NewLine);
                    sb.Append("\t     return dal.GetModel(");

                    List<string> list2 = new List<string>();
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        if (dr[5].ToString() != "int identity")
                        {
                            sb.Append(dr[3].ToString().ToString().Trim());
                        }
                    }
                    sb.Append(string.Join(",", list2.ToArray()));

                    sb.Append(");" + Environment.NewLine);
                    sb.Append("\t  }" + Environment.NewLine);
                }
            }
            #endregion
            #region GetMaxID
            if (GetMaxID)//GetMaxID
            {
                if (IdentityName != null)
                {

                }
                else if (listP.Count != 0)//主键
                {

                }
                else if (IdentityName == null && listP.Count == 0)//自增 and 主键 全无
                {
                }
            }
            #endregion
            #region GetList
            if (GetList)//GetList
            {
                //完成
                sb.Append("\t  /// <summary>" + Environment.NewLine + "\t  /// 获得数据列表" + Environment.NewLine + "\t  /// </summary>" + Environment.NewLine + Environment.NewLine);
                sb.Append("\t  public DataSet GetList(string strWhere)" + Environment.NewLine);
                sb.Append("\t  {" + Environment.NewLine);
                sb.Append("\t     return dal.GetList(strWhere);" + Environment.NewLine);
                sb.Append("\t  }" + Environment.NewLine);
                sb.Append("\t  /// <summary>" + Environment.NewLine + "\t  /// 获得数据列表" + Environment.NewLine + "\t  /// </summary>" + Environment.NewLine + Environment.NewLine);
                sb.Append("\t  public DataSet GetList()" + Environment.NewLine);
                sb.Append("\t  {" + Environment.NewLine);
                sb.Append("\t     return dal.GetList(" + '"' + '"' + ");" + Environment.NewLine);
                sb.Append("\t  }" + Environment.NewLine);
            }
            #endregion
            #region Exists
            if (Exists)//Exists
            {
                //完成

                sb.Append("\t  /// <summary>" + Environment.NewLine + "\t  /// 是否存在该记录" + Environment.NewLine + "\t  /// </summary>" + Environment.NewLine + Environment.NewLine);
                if (IdentityName != null)
                {
                    sb.Append("\t  public bool Exists(int " + IdentityName + " )" + Environment.NewLine);
                    sb.Append("\t  {" + Environment.NewLine);
                    sb.Append("\t     return dal.Exists(" + IdentityName + ");" + Environment.NewLine);
                    sb.Append("\t  }" + Environment.NewLine);
                }
                //else if (listP.Count != 0)//主键
                //{
                //    string DataType2 = "";
                //    foreach (DataRow dr in Columns.Tables[0].Rows)
                //    {
                //        if (dr[3].ToString() == listP[0].ToString())
                //        {
                //            DataType2 = DataType.ConvertType(dr[5].ToString());
                //            break;
                //        }
                //    }
                //    sb.Append("\t  public bool Exists(" + DataType2 + " " + listP[0].ToString().Trim() + " )" + Environment.NewLine);
                //    sb.Append("\t  {" + Environment.NewLine);
                //    sb.Append("\t     return dal.Exists(" + listP[0].ToString().Trim() + ");" + Environment.NewLine);
                //    sb.Append("\t  }" + Environment.NewLine);
                //}
                //else if (IdentityName == null && listP.Count == 0)//自增 AND 主键 全无
                //{
                //    sb.Append("\t  public bool Exists( ");
                //    List<string> list1 = new List<string>();
                //    foreach (DataRow dr in Columns.Tables[0].Rows)
                //    {
                //        list1.Add(DataType.ConvertType(dr[5].ToString() + " " + dr[3].ToString().ToString().Trim() + " "));
                //    }
                //    sb.Append(string.Join(",", list1.ToArray()));

                //    sb.Append(" )" + Environment.NewLine);
                //    sb.Append("\t  {" + Environment.NewLine);
                //    sb.Append("\t     return dal.Exists(");

                //    List<string> list2 = new List<string>();
                //    foreach (DataRow dr in Columns.Tables[0].Rows)
                //    {
                //        if (dr[5].ToString() != "int identity")
                //        {
                //            sb.Append(dr[3].ToString().ToString().Trim());
                //        }
                //    }
                //    sb.Append(string.Join(",", list2.ToArray()));

                //    sb.Append(");" + Environment.NewLine);
                //    sb.Append("\t  }" + Environment.NewLine);
                //}
            }
            #endregion
            sb.Append("\t  #endregion  成员方法" + Environment.NewLine);
            sb.Append("\t}" + Environment.NewLine);
            sb.Append("}" + Environment.NewLine);
            return sb;
        }
        #endregion

        #region 生成DAL
        /// <summary>
        /// 生成DAL
        /// </summary>
        /// <param name="TalbeName"></param>
        /// <param name="MakeBy"></param>
        /// <param name="add"></param>
        /// <param name="Update"></param>
        /// <param name="Delete"></param>
        /// <param name="GetModel"></param>
        /// <param name="GetList"></param>
        /// <param name="Exists"></param>
        /// <param name="GetMaxID"></param>
        /// <returns></returns>
        public static StringBuilder GetDALSB(string nameSpace, string TalbeName, bool MakeBy, bool add, bool Update, bool Delete, bool GetModel, bool GetList, bool Exists, bool GetMaxID)
        {
            DataSet Columns = Marker.GetColumns(TalbeName);
            string IdentityName = GetIndex(TalbeName);
            List<string> listP = pKeys(TalbeName);

            StringBuilder sb = new StringBuilder();
            sb.Append("using System;" + Environment.NewLine);
            sb.Append("using System.Data;" + Environment.NewLine);
            sb.Append("using System.Text;" + Environment.NewLine);
            sb.Append("using System.Collections.Generic;" + Environment.NewLine);
            sb.Append("using System.Data.SqlClient;" + Environment.NewLine);
            sb.Append("using System.Data.Common;" + Environment.NewLine);
            sb.Append("" + Environment.NewLine);
            if (!string.IsNullOrEmpty(nameSpace))
            {
                sb.Append("using " + nameSpace + ".Model;" + Environment.NewLine);
            }
            else
            {
                sb.Append("using Model;" + Environment.NewLine);
            }
            sb.Append("" + Environment.NewLine);
            sb.Append("" + Environment.NewLine);
            //sb.Append("using Maticsoft.DBUtility;//请先添加引用" + Environment.NewLine + Environment.NewLine);
            if (string.IsNullOrEmpty(nameSpace))
            {
                sb.Append("namespace DAL" + Environment.NewLine + "{" + Environment.NewLine);
            }
            else
            {
                sb.Append("namespace " + nameSpace + ".DAL" + Environment.NewLine + "{" + Environment.NewLine);
            }
            sb.Append("\t/// <summary>" + Environment.NewLine + "\t/// 数据访问类" + TalbeName + "。" + Environment.NewLine + "\t/// </summary>" + Environment.NewLine);
            sb.Append(" public class " + TalbeName + Environment.NewLine);
            sb.Append(" {" + Environment.NewLine);
            sb.Append("\tpublic " + TalbeName + "() {}" + Environment.NewLine);
            sb.Append("\t#region  成员方法" + Environment.NewLine);
            if (MakeBy)// "Maticsoft BUilderDALParam"
            {
                #region 基于Parameter方式
                #region ADD
                if (add)
                {
                    sb.Append("         /// <summary>" + Environment.NewLine);
                    sb.Append("         /// 增加一条数据" + Environment.NewLine);
                    sb.Append("         /// </summary>" + Environment.NewLine + Environment.NewLine);
                    sb.Append("         public int Add(Model." + TalbeName + " model)" + Environment.NewLine);

                    sb.Append("         {" + Environment.NewLine);
                    sb.Append("             StringBuilder strSql=new StringBuilder();" + Environment.NewLine);
                    sb.Append("             strSql.Append(" + '"' + "insert into " + TalbeName + "(" + '"' + ')' + ";" + Environment.NewLine);
                    sb.Append("             strSql.Append(" + '"');

                    List<string> tlist = new List<string>();
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        if (dr[5].ToString() != "int identity")
                        {
                            tlist.Add(dr[3].ToString());
                        }
                    }
                    sb.Append(string.Join(",", tlist.ToArray()));
                    sb.Append(")" + '"' + ");" + Environment.NewLine);
                    sb.Append("             strSql.Append(" + '"' + " values (" + '"' + ");" + Environment.NewLine);
                    sb.Append("             strSql.Append(" + '"');

                    List<string> tlist2 = new List<string>();
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        if (dr[5].ToString() != "int identity")
                        {
                            tlist2.Add(dr[3].ToString());
                        }
                    }
                    sb.Append(string.Join(",", tlist2.ToArray()));

                    sb.Append(")" + '"' + ");" + Environment.NewLine);
                    if (!string.IsNullOrEmpty(IdentityName))
                    {
                        sb.Append("             strSql.Append(" + '"' + ";select @@IDENTITY" + '"' + ");" + Environment.NewLine);
                    }
                    sb.Append("             SqlParameter[] parameters = {" + Environment.NewLine);

                    List<string> list1 = new List<string>();
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        if (dr[5].ToString() != "int identity")
                        {
                            if (dr[5].ToString() != "datetime" && dr[5].ToString() != "money" && dr[5].ToString() != "smdlldatatime" && dr[5].ToString() != "smdllmoney")
                            {
                                list1.Add("                 new SqlParameter(" + '"' + "@" + dr[3].ToString() + '"' + ",SqlDbType." + BuilderDALParamDataType.ConvertType(dr[5].ToString()) + "," + dr[7].ToString() + ")");
                            }
                            else if (dr[5].ToString() == "money" || dr[5].ToString() == "smdllmoney")
                            {
                                list1.Add("                 new SqlParameter(" + '"' + "@" + dr[5].ToString() + '"' + ",SqlDbType." + BuilderDALParamDataType.ConvertType(dr[5].ToString()) + ",8)");
                            }
                            else if (dr[5].ToString() == "datetime" || dr[5].ToString() == "smdlldatetime")
                            {
                                list1.Add("                 new SqlParameter(" + '"' + "@" + dr[3].ToString() + '"' + ",SqlDbType." + BuilderDALParamDataType.ConvertType(dr[5].ToString()) + ")");
                            }
                        }
                    }
                    sb.Append(string.Join("," + Environment.NewLine, list1.ToArray()));

                    sb.Append(Environment.NewLine + "             };" + Environment.NewLine);

                    int ParametersInt = 0;
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        if (dr[5].ToString() != "int identity")
                        {
                            sb.Append("            parameters[" + ParametersInt + "].Value = model." + upperLetter(dr[3].ToString()) + ";" + Environment.NewLine);
                            ParametersInt++;
                        }
                    }
                    if (!string.IsNullOrEmpty(IdentityName))
                    {
                        sb.Append("             object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);" + Environment.NewLine);
                        sb.Append("             if(obj == null)" + Environment.NewLine);
                        sb.Append("             {" + Environment.NewLine + "              return 1 ;" + Environment.NewLine + "             }" + Environment.NewLine);
                        sb.Append("              else" + Environment.NewLine);
                        sb.Append("             {" + Environment.NewLine);
                        sb.Append("               return Convert.ToInt32(obj);" + Environment.NewLine);
                        sb.Append("             }" + Environment.NewLine);
                    }
                    else
                    {
                        sb.Append("            return DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);" + Environment.NewLine);
                    }
                    sb.Append("         }" + Environment.NewLine);
                }
                #endregion
                #region Update
                if (Update)
                {
                    sb.Append("         /// <summary>" + Environment.NewLine + "         /// 更新一条数据" + Environment.NewLine + "         /// </summary>" + Environment.NewLine + Environment.NewLine);
                    sb.Append("         public void UpDate(Model." + TalbeName + " model)" + Environment.NewLine);
                    sb.Append("         {" + Environment.NewLine);
                    sb.Append("             StringBuilder strSql=new StringBuilder();" + Environment.NewLine);
                    sb.Append("             strSql.Append(" + '"' + "update " + TalbeName + " set" + '"' + ')' + ";" + Environment.NewLine);
                    sb.Append("             strSql.Append(" + '"');

                    List<string> tlist = new List<string>();
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        if (dr[5].ToString() != "int identity")
                        {
                            tlist.Add(dr[3].ToString() + "=@" + dr[3].ToString());
                        }
                    }
                    sb.Append(string.Join(",", tlist.ToArray()) + "\");" + Environment.NewLine);
                    sb.Append("             strSql.Append(" + '"' + " where ");

                    #region 添加条件

                    if (!string.IsNullOrEmpty(IdentityName))//自增
                    {
                        sb.Append(IdentityName + "=@" + IdentityName + " " + '"' + ");" + Environment.NewLine);
                    }
                    else //自增 AND 主键 全无
                    {
                        List<string> tlist2 = new List<string>();
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            if (dr[5].ToString() != "int identity")
                            {
                                tlist2.Add(dr[3].ToString() + "=@" + dr[3].ToString());
                            }
                        }
                        sb.Append(string.Join(" and ", tlist2.ToArray()));

                        sb.Append(" " + '"' + ");" + Environment.NewLine);
                    }
                    #endregion
                    sb.Append("             SqlParameter[] parameters = {" + Environment.NewLine);
                    List<string> tlist3 = new List<string>();
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        if (dr[5].ToString() != "datetime" && dr[5].ToString() != "money" && dr[5].ToString() != "smdlldatatime" && dr[5].ToString() != "smdllmoney")
                        {
                            tlist3.Add("                 new SqlParameter(" + '"' + "@" + dr[3].ToString() + '"' + ",SqlDbType." + BuilderDALParamDataType.ConvertType(dr[5].ToString()) + "," + dr[7].ToString() + ")");
                        }
                        else if (dr[5].ToString() == "money" || dr[5].ToString() == "smdllmoney")
                        {
                            tlist3.Add("                 new SqlParameter(" + '"' + "@" + dr[3].ToString() + '"' + ",SqlDbType." + BuilderDALParamDataType.ConvertType(dr[5].ToString()) + ",8)");
                        }
                        else if (dr[5].ToString() == "datetime" || dr[5].ToString() == "smdlldatetime")
                        {
                            tlist3.Add("                 new SqlParameter(" + '"' + "@" + dr[3].ToString() + '"' + ",SqlDbType." + BuilderDALParamDataType.ConvertType(dr[5].ToString()) + ")");
                        }
                    }
                    sb.Append(string.Join("," + Environment.NewLine, tlist3.ToArray()) + Environment.NewLine);
                    sb.Append("             };" + Environment.NewLine);

                    int ParametersInt = 0;
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        sb.Append("            parameters[" + ParametersInt + "].Value = model." + upperLetter(dr[3].ToString()) + ";" + Environment.NewLine);
                        ParametersInt++;
                    }
                    sb.Append("            DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);" + Environment.NewLine);
                    sb.Append("         }" + Environment.NewLine);
                }
                #endregion
                #region Delete
                if (Delete)
                {
                    sb.Append("\t/// <summary>" + Environment.NewLine + "\t/// 删除一条数据" + Environment.NewLine + "\t/// </summary>" + Environment.NewLine + Environment.NewLine);
                    //自增
                    if (!string.IsNullOrEmpty(IdentityName))
                    {
                        sb.Append("\tpublic void Delete(int " + IdentityName + ")" + Environment.NewLine);
                        sb.Append("\t {" + Environment.NewLine + "\t\tStringBuilder strSql=new StringBuilder();" + Environment.NewLine + "\t\tstrSql.Append(" + '"' + "delete " + TalbeName + " " + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tstrSql.Append(" + '"' + " where " + IdentityName + "=@" + IdentityName + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tSqlParameter[] parameters = {new SqlParameter(" + '"' + "@" + IdentityName + '"' + ", SqlDbType.Int,4)};" + Environment.NewLine);
                        sb.Append("\t\tparameters[0].Value = " + IdentityName + ";" + Environment.NewLine);
                        sb.Append("\t\tDbHelperSQL.ExecuteSql(strSql.ToString(),parameters);" + Environment.NewLine + "\t }" + Environment.NewLine);

                    }
                    //主键
                    else if (listP.Count != 0)
                    {
                        string DataType2 = "";
                        string DataType3 = "";
                        int DataLength = 0;
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            if (dr[3].ToString() == listP[0].ToString())
                            {
                                DataType2 = DataType.ConvertType(dr[5].ToString());
                                DataType3 = BuilderDALParamDataType.ConvertType(dr[5].ToString());
                                DataLength = Convert.ToInt32(dr[7].ToString());
                                break;
                            }
                        }
                        sb.Append("         public void Delete(" + DataType2.ToString() + " " + listP[0].ToString().Trim() + " )" + Environment.NewLine);
                        sb.Append("\t {" + Environment.NewLine + "\t\tStringBuilder strSql=new StringBuilder();" + Environment.NewLine + "\t\tstrSql.Append(" + '"' + "delete " + TalbeName + " " + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tstrSql.Append(" + '"' + " where " + listP[0].ToString() + "=@" + listP[0].ToString() + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tSqlParameter[] parameters = {" + Environment.NewLine + "\t\t\tnew SqlParameter(" + '"' + "@" + listP[0].ToString() + '"' + ", SqlDbType." + DataType3 + "," + DataLength + ")" + Environment.NewLine + "\t\t};" + Environment.NewLine);
                        sb.Append("\t\tparameters[0].Value = " + listP[0].ToString() + ";" + Environment.NewLine);
                        sb.Append("\t\tDbHelperSQL.ExecuteSql(strSql.ToString(),parameters);" + Environment.NewLine + "\t }" + Environment.NewLine);

                    }
                    //自增 AND 主键 全无
                    else
                    {
                        sb.Append("         public void Delete( ");
                        List<string> list1 = new List<string>();
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            list1.Add(DataType.ConvertType(dr[5].ToString()) + " " + dr[3].ToString().ToString().Trim() + " ");
                        }
                        sb.Append(string.Join(",", list1.ToArray()));

                        sb.Append(" )" + Environment.NewLine);
                        sb.Append("\t {" + Environment.NewLine + "\t\tStringBuilder strSql=new StringBuilder();" + Environment.NewLine + "\t\tstrSql.Append(" + '"' + "delete " + TalbeName + " " + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tstrSql.Append(" + '"' + "where ");
                        if (IdentityName == null)
                        {
                            List<string> list2 = new List<string>();
                            foreach (DataRow dr in Columns.Tables[0].Rows)
                            {
                                list2.Add(dr[3].ToString() + "=@" + dr[3].ToString());
                            }
                            sb.Append(string.Join(" and ", list2.ToArray()));

                            sb.Append(" " + '"' + ");" + Environment.NewLine);
                        }
                        sb.Append("\t\tSqlParameter[] parameters = {" + Environment.NewLine);

                        List<string> list3 = new List<string>();
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            if (dr[5].ToString() != "int identity")
                            {
                                if (dr[5].ToString() != "datetime" && dr[5].ToString() != "money" && dr[5].ToString() != "smdlldatatime" && dr[5].ToString() != "smdllmoney" && dr[5].ToString() != "bigint")
                                {
                                    list3.Add("                 new SqlParameter(" + '"' + "@" + dr[3].ToString() + '"' + ",SqlDbType." + BuilderDALParamDataType.ConvertType(dr[5].ToString()) + "," + dr[7].ToString() + ")");
                                }
                                else if (dr[5].ToString() == "money" || dr[5].ToString() == "smdllmoney")
                                {
                                    list3.Add("                 new SqlParameter(" + '"' + "@" + dr[3].ToString() + '"' + ",SqlDbType." + BuilderDALParamDataType.ConvertType(dr[5].ToString()) + ")");
                                }
                                else if (dr[5].ToString() == "datetime" || dr[5].ToString() == "smdlldatetime" || dr[5].ToString() == "bigint")
                                {
                                    list3.Add("                 new SqlParameter(" + '"' + "@" + dr[3].ToString() + '"' + ",SqlDbType." + BuilderDALParamDataType.ConvertType(dr[5].ToString()) + ")");
                                }
                            }

                        }
                        sb.Append(string.Join(",", list3.ToArray()));

                        sb.Append("             };" + Environment.NewLine);

                        int ParametersInt = 0;
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            if (dr[5].ToString() != "int identity")
                            {
                                sb.Append("            parameters[" + ParametersInt + "].Value = model." + dr[3].ToString() + ";" + Environment.NewLine);
                                ParametersInt++;
                            }

                        }
                        sb.Append("            DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);" + Environment.NewLine);
                        sb.Append("         }" + Environment.NewLine);
                    }
                }

                #endregion
                #region GetModel
                if (GetModel)
                {
                    sb.Append("\t/// <summary>" + Environment.NewLine + "\t/// 得到一个对象实体" + Environment.NewLine + "\t/// </summary>" + Environment.NewLine + Environment.NewLine);
                    //自增
                    if (IdentityName != null)
                    {
                        if (!string.IsNullOrEmpty(nameSpace))
                        {
                            sb.Append("   public " + nameSpace + ".Model." + TalbeName + " GetModel(int " + IdentityName + ")" + Environment.NewLine + "\t{" + Environment.NewLine);
                        }
                        else
                        {
                            sb.Append("   public Model." + TalbeName + " GetModel(int " + IdentityName + ")" + Environment.NewLine + "\t{" + Environment.NewLine);
                        }
                        sb.Append("\t\tStringBuilder strSql=new StringBuilder();" + Environment.NewLine);
                        sb.Append("\t\tstrSql.Append(" + '"' + "select ");
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            sb.Append(dr[3].ToString());
                        }

                        sb.Append(" from  " + TalbeName + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tstrSql.Append(" + '"' + " where " + IdentityName + "=@" + IdentityName + " " + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tSqlParameter[] parameters = { " + Environment.NewLine + "\t\tnew SqlParameter(" + '"' + "@" + IdentityName + '"' + ", SqlDbType.Int,4 )" + Environment.NewLine + " \t\t};" + Environment.NewLine);
                        sb.Append("\t\tparameters[0].Value = " + IdentityName + ";" + Environment.NewLine);
                        if (!string.IsNullOrEmpty(nameSpace))
                        {
                            sb.Append("\t\t" + nameSpace + ".Model." + TalbeName + " model = new " + nameSpace + ".Model." + TalbeName + "();" + Environment.NewLine);
                        }
                        else
                        {
                            sb.Append("\t\tModel." + TalbeName + " model = new Model." + TalbeName + "();" + Environment.NewLine);
                        }
                        sb.Append("\t\tDataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);" + Environment.NewLine);
                        sb.Append("\t\tif(ds.Tables[0].Rows.Count>0)" + Environment.NewLine);
                        sb.Append("\t\t{" + Environment.NewLine);
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            string GetType = dr[5].ToString();
                            if (DataType.ConvertType(GetType) == "int" && GetType != "money" && GetType != "smallmoney")
                            {
                                sb.Append("\t\t\tif(ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString()!=" + '"' + '"' + ")" + Environment.NewLine);
                                sb.Append("\t\t\t{" + Environment.NewLine);
                                sb.Append("\t\t\t\tmodel." + upperLetter(dr[3].ToString()) + "=int.Parse(ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString());" + Environment.NewLine);
                                sb.Append("\t\t\t}" + Environment.NewLine);
                            }
                            else if (GetType == "money" || GetType == "smallmoney")
                            {
                                sb.Append("\t\t\tif(ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString()!=" + '"' + '"' + ")" + Environment.NewLine);
                                sb.Append("\t\t\t{" + Environment.NewLine);
                                sb.Append("\t\t\t\tmodel." + upperLetter(dr[3].ToString()) + "=decimal.Parse(ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString());" + Environment.NewLine);
                                sb.Append("\t\t\t}" + Environment.NewLine);
                            }

                            else if (GetType == "datetime" || GetType == "smdlldatetime")
                            {
                                sb.Append("\t\t\tif(ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString()!=" + '"' + '"' + ")" + Environment.NewLine);
                                sb.Append("\t\t\t{" + Environment.NewLine);
                                sb.Append("\t\t\t\tmodel." + upperLetter(dr[3].ToString()) + "=DateTime.Parse(ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString());" + Environment.NewLine);
                                sb.Append("\t\t\t}" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append("\t\t\tmodel." + upperLetter(dr[3].ToString()) + "=ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString();" + Environment.NewLine);
                            }
                        }
                        sb.Append("\t\t\t return model;" + Environment.NewLine);
                        sb.Append("\t\t}" + Environment.NewLine);
                        sb.Append("\t\telse" + Environment.NewLine);
                        sb.Append("\t\t{" + Environment.NewLine);
                        sb.Append("\t\treturn null;" + Environment.NewLine);
                        sb.Append("\t\t}" + Environment.NewLine);
                        sb.Append("\t}" + Environment.NewLine);

                    }
                    //主键
                    else if (listP.Count != 0)
                    {
                        string DataType2 = "";
                        string DataType3 = "";
                        int DataLength = 0;
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            if (dr[3].ToString() == listP[0].ToString())
                            {
                                DataType2 = DataType.ConvertType(dr[5].ToString());
                                DataType3 = BuilderDALParamDataType.ConvertType(dr[5].ToString());
                                DataLength = Convert.ToInt32(dr[7].ToString());
                                break;
                            }
                        }
                        if (!string.IsNullOrEmpty(nameSpace))
                        {
                            sb.Append("\tpublic " + nameSpace + ".Model." + TalbeName + " GetModel(" + DataType2.ToString() + " " + listP[0].ToString().Trim() + " )" + Environment.NewLine);
                        }
                        else
                        {
                            sb.Append("\tpublic Model." + TalbeName + " GetModel(" + DataType2.ToString() + " " + listP[0].ToString().Trim() + " )" + Environment.NewLine);
                        }
                        sb.Append("\t {" + Environment.NewLine + "\t\tStringBuilder strSql=new StringBuilder();" + Environment.NewLine + "\t\tstrSql.Append(" + '"' + "select ");
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            sb.Append(dr[3].ToString());
                        }
                        sb.Append(" from " + TalbeName + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tstrSql.Append(" + '"' + " where " + listP[0] + "=@" + listP[0] + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tSqlParameter[] parameters = { " + Environment.NewLine + "\t\t  new SqlParameter(" + '"' + "@" + listP[0].Trim() + '"' + ", SqlDbType." + DataType3 + "," + DataLength + " )" + Environment.NewLine + " \t\t};" + Environment.NewLine);
                        sb.Append("\t\tparameters[0].Value = " + listP[0].Trim() + ";" + Environment.NewLine);

                        if (!string.IsNullOrEmpty(nameSpace))
                        {
                            sb.Append("\t\tModel." + nameSpace + "." + TalbeName + " model=new Model." + nameSpace + "." + TalbeName + "();" + Environment.NewLine);
                        }
                        else
                        {
                            sb.Append("\t\tModel." + TalbeName + " model=new Model." + TalbeName + "();" + Environment.NewLine);
                        }
                        sb.Append("\t\tDataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);" + Environment.NewLine);

                        sb.Append("\t\tif(ds.Tables[0].Rows.Count>0)" + Environment.NewLine);
                        sb.Append("\t\t{" + Environment.NewLine);
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            string GetType = dr[5].ToString();
                            if (DataType.ConvertType(GetType) == "int" && GetType != "money" && GetType != "smallmoney")
                            {
                                sb.Append("\t\t\tif(ds.Tables[0].Rows[0][" + '"' + upperLetter(dr[3].ToString()) + '"' + "].ToString()!=" + '"' + '"' + ")" + Environment.NewLine);
                                sb.Append("\t\t\t{" + Environment.NewLine);
                                sb.Append("\t\t\t\tmodel." + upperLetter(dr[3].ToString()) + "=int.Parse(ds.Tables[0].Rows[0][" + '"' + upperLetter(dr[3].ToString()) + '"' + "].ToString());" + Environment.NewLine);
                                sb.Append("\t\t\t}" + Environment.NewLine);
                            }
                            else if (GetType == "money" || GetType == "smallmoney")
                            {
                                sb.Append("\t\t\tif(ds.Tables[0].Rows[0][" + '"' + upperLetter(dr[3].ToString()) + '"' + "].ToString()!=" + '"' + '"' + ")" + Environment.NewLine);
                                sb.Append("\t\t\t{" + Environment.NewLine);
                                sb.Append("\t\t\t\tmodel." + upperLetter(dr[3].ToString()) + "=decimal.Parse(ds.Tables[0].Rows[0][" + '"' + upperLetter(dr[3].ToString()) + '"' + "].ToString());" + Environment.NewLine);
                                sb.Append("\t\t\t}" + Environment.NewLine);
                            }

                            else if (GetType == "datetime" || GetType == "smdlldatetime")
                            {
                                sb.Append("\t\t\tif(ds.Tables[0].Rows[0][" + '"' + upperLetter(dr[3].ToString()) + '"' + "].ToString()!=" + '"' + '"' + ")" + Environment.NewLine);
                                sb.Append("\t\t\t{" + Environment.NewLine);
                                sb.Append("\t\t\t\tmodel." + upperLetter(dr[3].ToString()) + "=DateTime.Parse(ds.Tables[0].Rows[0][" + '"' + upperLetter(dr[3].ToString()) + '"' + "].ToString());" + Environment.NewLine);
                                sb.Append("\t\t\t}" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append("\t\t\tmodel." + upperLetter(dr[3].ToString()) + "=ds.Tables[0].Rows[0][" + '"' + upperLetter(dr[3].ToString()) + '"' + "].ToString();" + Environment.NewLine);
                            }
                        }
                        sb.Append("\t\t\t return model;" + Environment.NewLine);
                        sb.Append("\t\t}" + Environment.NewLine);
                        sb.Append("\t\telse" + Environment.NewLine);
                        sb.Append("\t\t{" + Environment.NewLine);
                        sb.Append("\t\treturn null;" + Environment.NewLine);
                        sb.Append("\t\t}" + Environment.NewLine);
                        sb.Append("\t}" + Environment.NewLine);

                    }
                    //自增 AND 主键 全无
                    else
                    {
                        sb.Append("         public Maticsoft.Model." + TalbeName + " GetModel( ");
                        List<string> list3 = new List<string>();
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            list3.Add(DataType.ConvertType(dr[5].ToString()) + " " + dr[3].ToString().ToString().Trim() + " ");
                        }
                        sb.Append(string.Join(",", list3.ToArray()));

                        sb.Append(" )" + Environment.NewLine);
                        sb.Append("\t {" + Environment.NewLine + "\t\tStringBuilder strSql=new StringBuilder();" + Environment.NewLine);
                        sb.Append("\t\tstrSql.Append(" + '"' + "select ");

                        List<string> list4 = new List<string>();
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            sb.Append(dr[3].ToString());
                        }
                        sb.Append(string.Join(",", list4.ToArray()));

                        sb.Append(" " + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tstrSql.Append(" + '"' + "where ");

                        List<string> list5 = new List<string>();
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            sb.Append(dr[3].ToString() + "=@" + dr[3].ToString());
                        }
                        sb.Append(string.Join(" and ", list5.ToArray()));
                        sb.Append(" " + '"' + ");" + Environment.NewLine);

                        sb.Append("\t\tSqlParameter[] parameters = {" + Environment.NewLine);

                        List<string> list6 = new List<string>();
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            if (dr[5].ToString() != "int identity")
                            {
                                if (dr[5].ToString() != "datetime" && dr[5].ToString() != "money" && dr[5].ToString() != "smdlldatatime" && dr[5].ToString() != "smdllmoney" && dr[5].ToString() != "bigint")
                                {
                                    sb.Append("\t\tnew SqlParameter(" + '"' + "@" + dr[3].ToString() + '"' + ",SqlDbType." + BuilderDALParamDataType.ConvertType(dr[5].ToString()) + "," + dr[7].ToString() + ")");
                                }
                                else if (dr[5].ToString() == "money" || dr[5].ToString() == "smdllmoney")
                                {
                                    sb.Append("\t\tnew SqlParameter(" + '"' + "@" + dr[3].ToString() + '"' + ",SqlDbType." + BuilderDALParamDataType.ConvertType(dr[5].ToString()) + ")");
                                }
                                else if (dr[5].ToString() == "datetime" || dr[5].ToString() == "smdlldatetime" || dr[5].ToString() == "bigint")
                                {
                                    sb.Append("\t\tnew SqlParameter(" + '"' + "@" + dr[3].ToString() + '"' + ",SqlDbType." + BuilderDALParamDataType.ConvertType(dr[5].ToString()) + ")");
                                }
                            }

                        }
                        sb.Append(string.Join(" and ", list6.ToArray()));
                        sb.Append("             };" + Environment.NewLine);
                        int ParametersInt = 0;
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            if (dr[5].ToString() != "int identity")
                            {
                                sb.Append("\t\tparameters[" + ParametersInt + "].Value = model." + dr[3].ToString() + ";" + Environment.NewLine);
                                ParametersInt++;
                            }

                        }
                        sb.Append("\t\tMaticsoft.Model.tb_Application model=new Maticsoft.Model.tb_Application();" + Environment.NewLine);
                        sb.Append("\t\tDataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);" + Environment.NewLine);

                        sb.Append("\t\tif(ds.Tables[0].Rows.Count>0)" + Environment.NewLine);
                        sb.Append("\t\t{" + Environment.NewLine);
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            string GetType = dr[5].ToString();
                            if (DataType.ConvertType(GetType) == "int" && GetType != "money" && GetType != "smallmoney")
                            {
                                sb.Append("\t\t\tif(ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString()!=" + '"' + '"' + ")" + Environment.NewLine);
                                sb.Append("\t\t\t{" + Environment.NewLine);
                                sb.Append("\t\t\t\tmodel." + dr[3].ToString() + "=int.Parse(ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString());" + Environment.NewLine);
                                sb.Append("\t\t\t}" + Environment.NewLine);
                            }
                            else if (GetType == "money" || GetType == "smallmoney")
                            {
                                sb.Append("\t\t\tif(ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString()!=" + '"' + '"' + ")" + Environment.NewLine);
                                sb.Append("\t\t\t{" + Environment.NewLine);
                                sb.Append("\t\t\t\tmodel." + dr[3].ToString() + "=decimal.Parse(ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString());" + Environment.NewLine);
                                sb.Append("\t\t\t}" + Environment.NewLine);
                            }
                            else if (GetType == "datetime" || GetType == "smdlldatetime")
                            {
                                sb.Append("\t\t\tif(ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString()!=" + '"' + '"' + ")" + Environment.NewLine);
                                sb.Append("\t\t\t{" + Environment.NewLine);
                                sb.Append("\t\t\t\tmodel." + dr[3].ToString() + "=DateTime.Parse(ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString());" + Environment.NewLine);
                                sb.Append("\t\t\t}" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append("\t\t\tmodel." + dr[3].ToString() + "=ds.Tables[0].Rows[0][" + '"' + dr[3].ToString() + '"' + "].ToString();" + Environment.NewLine);
                            }
                        }
                        sb.Append("\t\t\t return model;" + Environment.NewLine);
                        sb.Append("\t\t}" + Environment.NewLine);
                        sb.Append("\t\telse" + Environment.NewLine);
                        sb.Append("\t\t{" + Environment.NewLine);
                        sb.Append("\t\treturn null;" + Environment.NewLine);
                        sb.Append("\t\t}" + Environment.NewLine);
                        sb.Append("\t}" + Environment.NewLine);
                    }
                }
                #endregion
                #region GetList
                if (GetList)
                {
                    sb.Append("\t/// <summary>" + Environment.NewLine + "\t/// 获得数据列表" + Environment.NewLine + "\t/// </summary>" + Environment.NewLine + Environment.NewLine);
                    sb.Append("\tpublic DataSet GetList(string strWhere)" + Environment.NewLine);
                    sb.Append("\t{" + Environment.NewLine);
                    sb.Append("\t\tStringBuilder strSql=new StringBuilder();" + Environment.NewLine);
                    sb.Append("\t\tstrSql.Append(" + '"' + "select " + " ");
                    List<string> list1 = new List<string>();
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        list1.Add(dr[3].ToString());
                    }
                    sb.Append(string.Join(", ", list1.ToArray()));

                    sb.Append("" + '"' + ");" + Environment.NewLine);
                    sb.Append("\t\tstrSql.Append(" + '"' + " FROM " + TalbeName + " " + '"' + ");" + Environment.NewLine);
                    sb.Append("\t\tif(strWhere.Trim()!=" + '"' + '"' + ")" + Environment.NewLine);
                    sb.Append("\t\t{" + Environment.NewLine);
                    sb.Append("\t\t\tstrSql.Append(" + '"' + " where " + '"' + "+strWhere);" + Environment.NewLine);
                    sb.Append("\t\t}" + Environment.NewLine);
                    sb.Append("\t\treturn DbHelperSQL.Query(strSql.ToString());" + Environment.NewLine);
                    sb.Append("\t}" + Environment.NewLine);

                }
                #endregion
                #region Exists
                if (Exists)
                {
                    sb.Append("\t/// <summary>" + Environment.NewLine + "\t/// 是否存在该记录" + Environment.NewLine + "\t/// </summary>" + Environment.NewLine + Environment.NewLine);
                    //自增
                    if (IdentityName != null)
                    {
                        sb.Append("\tpublic bool Exists(int " + IdentityName.Trim() + ")" + Environment.NewLine);
                        sb.Append("\t{" + Environment.NewLine);
                        sb.Append("\t\tStringBuilder strSql=new StringBuilder();" + Environment.NewLine);
                        sb.Append("\t\tstrSql.Append(" + '"' + "select count(1) from " + TalbeName + " " + " ");
                        sb.Append("" + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tstrSql.Append(" + '"' + " FROM " + TalbeName + " " + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tSqlParameter[] parameters = { new SqlParameter(" + '"' + "@" + IdentityName.Trim() + '"' + ", SqlDbType.Int,4) };" + Environment.NewLine);
                        sb.Append("\t\tparameters[0].Value = " + IdentityName.Trim() + ";" + Environment.NewLine);
                        sb.Append("\t\treturn DbHelperSQL.Exists(strSql.ToString(),parameters);" + Environment.NewLine);
                        sb.Append("\t}" + Environment.NewLine);
                    }
                }
                #endregion
                #region GetMaxID
                if (GetMaxID)
                {
                }
                #endregion
                #endregion
            }
            else //"BuilderDALELParam"
            {
                #region 基于企业库Param方式
                #region ADD
                if (add)//add
                {
                    sb.Append("         /// <summary>" + Environment.NewLine);
                    sb.Append("         /// 增加一条数据" + Environment.NewLine);
                    sb.Append("         /// </summary>" + Environment.NewLine + Environment.NewLine);
                    sb.Append("         public void Add(Model." + TalbeName + " model)" + Environment.NewLine);

                    sb.Append("         {" + Environment.NewLine);
                    sb.Append("             StringBuilder strSql=new StringBuilder();" + Environment.NewLine);
                    sb.Append("             strSql.Append(" + '"' + "insert into " + TalbeName + "(" + '"' + ')' + ";" + Environment.NewLine);

                    sb.Append("             strSql.Append(" + '"');

                    List<string> list1 = new List<string>();
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        if (dr[5].ToString() != "int identity")
                        {
                            list1.Add(dr[3].ToString());
                        }
                    }
                    sb.Append(string.Join(",", list1.ToArray()));

                    sb.Append(")" + '"' + ");" + Environment.NewLine);
                    sb.Append("             strSql.Append(" + '"' + " values (" + '"' + ");" + Environment.NewLine);
                    sb.Append("             strSql.Append(" + '"');

                    List<string> list2 = new List<string>();
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        if (dr[5].ToString() != "int identity")
                        {
                            list2.Add("@" + dr[3].ToString());
                        }
                    }
                    sb.Append(string.Join(",", list2.ToArray()));
                    sb.Append(")" + '"' + ");" + Environment.NewLine);
                    if (!string.IsNullOrEmpty(IdentityName))
                    {
                        sb.Append("             strSql.Append(" + '"' + ";select @@IDENTITY" + '"' + ");" + Environment.NewLine);
                    }
                    sb.Append("             Database db = DatabaseFactory.CreateDatabase();" + Environment.NewLine);
                    sb.Append("             DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());" + Environment.NewLine);
                    //zhe  xia  mian ;
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        if (dr[5].ToString() != "int identity")
                        {

                            sb.Append("                 db.AddInParameter(dbCommand, " + '"' + dr[3].ToString() + '"' + ",DbType." + BuilderDALELParam.ConvertType(dr[5].ToString()) + ",model." + dr[3].ToString() + ");" + Environment.NewLine);

                        }
                    }

                    if (!string.IsNullOrEmpty(IdentityName))
                    {
                        sb.Append("             int result;" + Environment.NewLine);
                        sb.Append("             object obj = db.ExecuteScalar(dbCommand);" + Environment.NewLine);
                        sb.Append("             if(!int.TryParse(obj.ToString(),out result))" + Environment.NewLine);
                        sb.Append("             {" + Environment.NewLine + "              return 0 ;" + Environment.NewLine + "             }" + Environment.NewLine);
                        sb.Append("             return result;" + Environment.NewLine);

                    }
                    else
                    {
                        sb.Append("           db.ExecuteNonQuery(dbCommand);" + Environment.NewLine);
                    }
                    sb.Append("         }" + Environment.NewLine);
                }
                #endregion
                #region Update
                if (Update)//Update
                {
                    sb.Append("         /// <summary>" + Environment.NewLine + "         /// 更新一条数据" + Environment.NewLine + "         /// </summary>" + Environment.NewLine + Environment.NewLine);
                    sb.Append("         public void UpDate(Model." + TalbeName + " model)" + Environment.NewLine);
                    sb.Append("         {" + Environment.NewLine);
                    sb.Append("             StringBuilder strSql=new StringBuilder();" + Environment.NewLine);
                    sb.Append("             strSql.Append(" + '"' + "update " + TalbeName + " set" + '"' + ')' + ";" + Environment.NewLine);

                    sb.Append("             strSql.Append(" + '"');
                    List<string> list1 = new List<string>();
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        if (dr[5].ToString() != "int identity")
                        {
                            list1.Add(dr[3].ToString() + "=@" + dr[3].ToString());
                        }
                    }
                    sb.Append(string.Join(",", list1.ToArray()));
                    sb.Append('"' + ");" + Environment.NewLine);
                    sb.Append("             strSql.Append(" + '"' + " where ");

                    //自增
                    if (IdentityName != null)
                    {
                        sb.Append(IdentityName + "=@" + IdentityName + " " + '"' + ");" + Environment.NewLine);
                    }
                    else if (listP.Count != 0)//主键
                    {
                        sb.Append(listP[0].ToString() + "=@" + listP[0].ToString() + " " + '"' + ");" + Environment.NewLine);
                    }
                    else if (IdentityName == null && listP.Count == 0) //自增 AND 主键 全无
                    {
                        List<string> list2 = new List<string>();
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            list2.Add(dr[3].ToString() + "=@" + dr[3].ToString());
                        }

                        sb.Append(string.Join(" and ", list2.ToArray()));
                        sb.Append(" " + '"' + ");" + Environment.NewLine);
                    }



                    sb.Append("             Database db = DatabaseFactory.CreateDatabase();" + Environment.NewLine);
                    sb.Append("             DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());" + Environment.NewLine);
                    foreach (DataRow dr in Columns.Tables[0].Rows)
                    {
                        sb.Append("             db.AddInParameter(dbCommand," + '"' + dr[3].ToString() + '"' + ",DbType." + BuilderDALELParam.ConvertType(dr[5].ToString()) + ", model." + dr[3].ToString() + ");" + Environment.NewLine);
                    }
                    sb.Append("             db.ExecuteNonQuery(dbCommand);" + Environment.NewLine);
                    sb.Append("         }" + Environment.NewLine);
                }
                #endregion
                #region Delete
                if (Delete)//Delete
                {
                    //完成
                    sb.Append("\t/// <summary>" + Environment.NewLine + "\t/// 删除一条数据" + Environment.NewLine + "         /// </summary>" + Environment.NewLine + Environment.NewLine);


                    //自增
                    if (IdentityName != null)
                    {

                        sb.Append("\tpublic void Delete(int " + IdentityName.ToString().Trim() + ")" + Environment.NewLine);
                        sb.Append("\t {" + Environment.NewLine + "\t\tStringBuilder strSql=new StringBuilder();" + Environment.NewLine + "\t\tstrSql.Append(" + '"' + "delete " + TalbeName + " " + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tstrSql.Append(" + '"' + " where " + IdentityName + "=@" + IdentityName + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tDatabase db = DatabaseFactory.CreateDatabase();" + Environment.NewLine);
                        sb.Append("\t\tDbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());" + Environment.NewLine);
                        sb.Append("\t\tdb.AddInParameter(dbCommand, " + '"' + IdentityName + '"' + ", DbType.Int32," + IdentityName + ");" + Environment.NewLine);
                        sb.Append("\t\tdb.ExecuteNonQuery(dbCommand);" + Environment.NewLine + "\t }" + Environment.NewLine);
                    }
                    //主键
                    else if (listP.Count != 0)
                    {
                        string DataType2 = "";
                        string DataType3 = "";
                        int DataLength = 0;
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            if (dr[3].ToString() == listP[0].ToString())
                            {
                                DataType2 = DataType.ConvertType(dr[5].ToString());
                                DataType3 = BuilderDALELParam.ConvertType(dr[5].ToString());
                                DataLength = Convert.ToInt32(dr[7].ToString());
                                break;
                            }
                        }
                        sb.Append("         public void Delete(" + DataType2.ToString() + " " + listP[0].ToString().Trim() + " )" + Environment.NewLine);
                        sb.Append("\t {" + Environment.NewLine + "\t\tStringBuilder strSql=new StringBuilder();" + Environment.NewLine + "\t\tstrSql.Append(" + '"' + "delete " + TalbeName + " " + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tstrSql.Append(" + '"' + " where " + listP[0].ToString() + "=@" + listP[0].ToString() + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tDatabase db = DatabaseFactory.CreateDatabase();" + Environment.NewLine);
                        sb.Append("\t\tDbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());" + Environment.NewLine);
                        sb.Append("\t\tdb.AddInParameter(dbCommand, " + '"' + listP[0].ToString() + '"' + ", DbType." + DataType3 + "," + listP[0].ToString() + ")};" + Environment.NewLine);
                        sb.Append("\t\tdb.ExecuteNonQuery(dbCommand);" + Environment.NewLine + "\t }" + Environment.NewLine);

                    }
                    //自增 AND 主键 全无
                    else
                    {

                        sb.Append("         public void Delete( ");
                        List<string> list1 = new List<string>();
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            list1.Add(DataType.ConvertType(dr[5].ToString() + " " + dr[3].ToString() + " "));

                        }
                        sb.Append(string.Join(",", list1.ToArray()));

                        sb.Append(" )" + Environment.NewLine);
                        sb.Append("\t {" + Environment.NewLine + "\t\tStringBuilder strSql=new StringBuilder();" + Environment.NewLine + "\t\tstrSql.Append(" + '"' + "delete " + TalbeName + " " + '"' + ");" + Environment.NewLine);
                        sb.Append("\t\tstrSql.Append(" + '"' + "where ");
                        if (IdentityName == null)
                        {
                            List<string> list2 = new List<string>();
                            foreach (DataRow dr in Columns.Tables[0].Rows)
                            {
                                list2.Add(dr[3].ToString() + "=@" + dr[3].ToString());

                            }
                            sb.Append(string.Join(" and ", list2.ToArray()));

                            sb.Append(" " + '"' + ");" + Environment.NewLine);
                        }
                        sb.Append("\t\tDatabase db = DatabaseFactory.CreateDatabase();" + Environment.NewLine);
                        sb.Append("\t\tDbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());" + Environment.NewLine);
                        foreach (DataRow dr in Columns.Tables[0].Rows)
                        {
                            if (dr[5].ToString() != "int identity")
                            {
                                sb.Append("\t\tdb.AddInParameter(dbCommand, " + '"' + dr[3].ToString() + '"' + ", DbType." + BuilderDALELParam.ConvertType(dr[5].ToString()) + "," + dr[3].ToString() + ");" + Environment.NewLine);
                            }
                        }

                        sb.Append("            db.ExecuteNonQuery(dbCommand);" + Environment.NewLine);
                        sb.Append("         }" + Environment.NewLine);
                    }


                }
                #endregion
                #endregion
            }
            sb.Append("\t#endregion  成员方法" + Environment.NewLine);
            sb.Append(" }" + Environment.NewLine);
            sb.Append("}" + Environment.NewLine);
            return sb;
        }
        #endregion

        #region 根据用户设置生成代码
        /// <summary>
        /// 根据用户设置生成代码
        /// </summary>
        /// <param name="choice">用户设置组合</param>
        /// <returns></returns>
        private static string setsb(string TalbeName, int choice)
        {
            StringBuilder sb = new StringBuilder();
            List<string> listP = pKeys(TalbeName);
            switch (choice)
            {
                case 1:
                    sb.AppendLine("    public class " + TalbeName + " : IComparable<" + TalbeName + ">");
                    sb.AppendLine("    {");
                    sb.Append(setAttribute(TalbeName, 2));
                    sb.Append(setCompareTo(TalbeName, listP[0], 2, true));
                    sb.AppendLine("    }");
                    sb.AppendLine("}");
                    break;
                case 2:
                    sb.AppendLine("    public class " + TalbeName + " : IComparable");
                    sb.AppendLine("    {");
                    sb.Append(setAttribute(TalbeName, 2));
                    sb.Append(setCompareTo(TalbeName, listP[0], 2, false));
                    sb.AppendLine("    }");
                    sb.AppendLine("}");
                    break;
                case 3:
                    sb.AppendLine("    public class " + TalbeName);
                    sb.AppendLine("    {");
                    sb.Append(setAttribute(TalbeName, 2));
                    sb.AppendLine("    }");
                    sb.AppendLine("");
                    sb.Append(setComparers(TalbeName, TalbeName, 1));
                    sb.AppendLine("}");
                    break;
                case 4:
                    sb.AppendLine("    public class " + TalbeName + " : IComparable<" + TalbeName + ">");
                    sb.AppendLine("    {");
                    sb.Append(setAttribute(TalbeName, 2));
                    sb.Append(setCompareTo(TalbeName, listP[0], 2, true));
                    sb.AppendLine("    }");
                    sb.AppendLine("");
                    sb.Append(setComparers(TalbeName, TalbeName, 1));
                    sb.AppendLine("}");
                    break;
                case 5:
                    sb.AppendLine("    public class " + TalbeName + " : IComparable");
                    sb.AppendLine("    {");
                    sb.Append(setAttribute(TalbeName, 2));
                    sb.Append(setCompareTo(TalbeName, listP[0], 2, false));
                    sb.AppendLine("    }");
                    sb.AppendLine("");
                    sb.Append(setComparers(TalbeName, TalbeName, 1));
                    sb.AppendLine("}");
                    break;
                case 6:
                    sb.AppendLine("    public class " + TalbeName);
                    sb.AppendLine("    {");
                    sb.Append(setAttribute(TalbeName, 2));
                    sb.AppendLine("    }");
                    sb.AppendLine("}");
                    break;
            }
            return sb.ToString();
        }
        #endregion

        #region 根据当前存储的attName和attType生成所有字段的成员变量和公共属性
        /// <summary>
        /// 根据当前存储的attName和attType生成所有字段的成员变量和公共属性
        /// </summary>
        /// <param name="count">空格缩进数</param>
        /// <returns></returns>
        private static string setAttribute(string TalbeName, int count)
        {
            StringBuilder str = new StringBuilder();
            str.AppendLine(setSpace(count) + "#region 成员变量和公共属性");

            DataSet rTalbes = GetColumns(TalbeName);
            foreach (DataRow dr in rTalbes.Tables[0].Rows)
            {
                str.AppendLine(setSpace(count) + "private " + getType(dr[5].ToString()) + " _" + dr[3].ToString() + ";");
                str.AppendLine(setSpace(count) + "public " + getType(dr[5].ToString()) + " " + upperLetter(dr[3].ToString()));
                str.AppendLine(setSpace(count) + "{");
                str.AppendLine(setSpace(++count) + "set{ _" + dr[3].ToString() + " = value; }");
                str.AppendLine(setSpace(count) + "get{ return _" + dr[3].ToString() + "; }");
                str.AppendLine(setSpace(--count) + "}");
                str.AppendLine("");
            }

            str.AppendLine(setSpace(count) + "#endregion");
            str.AppendLine("");
            return str.ToString();
        }
        #endregion

        #region 生成缩进空格
        /// <summary>
        /// 生成缩进空格
        /// </summary>
        /// <param name="count">缩进次数</param>
        /// <returns></returns>
        private static string setSpace(int count)
        {
            StringBuilder str = new StringBuilder();
            for (int i = 0; i < count; i++)
                str.Append("    ");
            return str.ToString();
        }
        #endregion

        #region 根据获得的SQL数据类型名返回C#数据类型名
        /// <summary>
        /// 根据获得的SQL数据类型名返回C#数据类型名
        /// </summary>
        /// <param name="typeName">SQL数据类型名</param>
        /// <returns>对应的C#数据类型名</returns>
        private static string getType(string typeName)
        {
            switch (typeName.ToLower())
            {
                case "bigint":
                    return "int";
                case "binary":
                    return "byte[]";
                case "bit":
                    return "bool";
                case "char":
                    return "string";
                case "datetime":
                    return "string";
                case "decimal":
                    return "double";
                case "image":
                    return "byte[]";
                case "money":
                    return "float";
                case "nchar":
                    return "string";
                case "ntext":
                    return "string";
                case "numeric":
                    return "double";
                case "nvarchar":
                    return "string";
                case "real":
                    return "double";
                case "smalldatetime":
                    return "string";
                case "smallint":
                    return "int";
                case "smallmoney":
                    return "float";
                case "text":
                    return "string";
                case "tinyint":
                    return "int";
                case "varbinary":
                    return "byte[]";
                case "varchar":
                    return "string";
                case "int identity":
                    return "int";
                default:
                    return typeName.ToLower();
            }
        }
        #endregion

        #region 根据字段生成比较器代码
        /// <summary>
        /// 根据字段生成比较器代码
        /// </summary>
        /// <param name="count">缩进空格数</param>
        /// <returns></returns>
        private static string setComparers(string TalbeName, string className, int count)
        {
            int _count = count;
            StringBuilder str = new StringBuilder();
            str.AppendLine(setSpace(count) + "#region 实现IComparers<T>接口的泛型排序方法");
            DataSet rTalbes = GetColumns(TalbeName);
            foreach (DataRow dr in rTalbes.Tables[0].Rows)
            {
                count = _count;
                str.Append(setAnnotate(new string[] { "x", "y" }, count, true, "根据" + upperLetter(dr[3].ToString()) + "生成的升序比较器"));
                str.AppendLine(setSpace(count) + "public class " + upperLetter(dr[3].ToString()) + "Comparer : IComparer<" + className + ">");
                str.AppendLine(setSpace(count) + "{");
                str.AppendLine(setSpace(++count) + "public int Compare(" + className + " x, " + className + " y)");
                str.AppendLine(setSpace(count) + "{");
                str.AppendLine(setSpace(++count) + "return x." + upperLetter(dr[3].ToString()) + ".CompareTo(y." + upperLetter(dr[3].ToString()) + ");");
                str.AppendLine(setSpace(--count) + "}");
                str.AppendLine(setSpace(--count) + "}");
                str.AppendLine("");
                count = _count;
                str.Append(setAnnotate(new string[] { "x", "y" }, count, true, "根据" + upperLetter(dr[3].ToString()) + "生成的降序比较器"));
                str.AppendLine(setSpace(count) + "public class " + upperLetter(dr[3].ToString()) + "ComparerDesc : IComparer<" + className + ">");
                str.AppendLine(setSpace(count) + "{");
                str.AppendLine(setSpace(++count) + "public int Compare(" + className + " x, " + className + " y)");
                str.AppendLine(setSpace(count) + "{");
                str.AppendLine(setSpace(++count) + "return y." + upperLetter(dr[3].ToString()) + ".CompareTo(x." + upperLetter(dr[3].ToString()) + ");");
                str.AppendLine(setSpace(--count) + "}");
                str.AppendLine(setSpace(--count) + "}");
                str.AppendLine("");
            }
            str.AppendLine(setSpace(count) + "#endregion");
            return str.ToString();
        }
        #endregion

        #region 生成泛型排序代码
        /// <summary>
        /// 生成泛型排序代码
        /// </summary>
        /// <param name="count">缩进空格数</param>
        /// <param name="isList">是否用IComparerable泛型版本</param>
        /// <returns></returns>
        private static string setCompareTo(string TalbeName,string lpKeys, int count, bool isList)
        {
            StringBuilder str = new StringBuilder();
            str.AppendLine(setSpace(count) + "#region 实现" + (isList ? "IComparable<T>" : "IComparable") + "接口的泛型排序方法");
            str.Append(setAnnotate(new string[] { "other" }, count, false, "根据" + upperLetter(TalbeName) + "字段实现的" + (isList ? "IComparable<T>" : "IComparable") + "接口的泛型排序方法"));
            str.AppendLine(setSpace(count) + "public int CompareTo(" + (isList ? TalbeName : "object") + " other)");
            str.AppendLine(setSpace(count) + "{");
            str.AppendLine(setSpace(++count) + "return " + upperLetter(lpKeys) + ".CompareTo(other." + upperLetter(lpKeys) + ");");
            str.AppendLine(setSpace(--count) + "}");
            str.AppendLine(setSpace(count) + "#endregion");
            return str.ToString();
            //return null;
        }
        #endregion

        #region 生成注释代码
        /// <summary>
        /// 根据参数名数组生成C#代码注释
        /// </summary>
        /// <param name="paramNames">参数名数组</param>
        /// <param name="count">缩进空格数</param>
        /// <returns></returns>
        private static string setAnnotate(string[] paramNames, int count, bool isClass, string classInfo)
        {
            StringBuilder str = new StringBuilder();
            str.AppendLine(setSpace(count) + "/// <sumary> ");
            str.AppendLine(setSpace(count) + "/// " + classInfo + " ");
            str.AppendLine(setSpace(count) + "/// </sumary> ");
            if (!isClass)
            {
                foreach (string name in paramNames)
                    str.AppendLine(setSpace(count) + "/// <param name=\"" + name + "\"></param> ");
                str.AppendLine(setSpace(count) + "/// <returns></returns> ");
            }
            return str.ToString();
        }
        #endregion

        #region 将传入的字符串首字母大写
        /// <summary>
        /// 将传入的字符串首字母大写
        /// </summary>
        /// <param name="str">字符串</param>
        /// <returns></returns>
        public static string upperLetter(string str)
        {
            if (str.Length > 1)
            {
                string str1 = str.ToUpper();
                return str1[0].ToString() + str.Substring(1, str.Length - 1);
            }
            else
                return str.ToUpper();
        }
        #endregion
    }
}
